home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / SQLRUN.CAB / sp1ServUni.sql.6EAD8B17_4094_442C_BF0E_93C639158E73 < prev    next >
Encoding:
Text (UTF-16)  |  2001-04-13  |  137.4 KB  |  2,307 lines

  1. /*------------------------------------------------------------------------------
  2.  
  3. SP1_SERV.SQL
  4.  
  5. THIS SCRIPT TAKES THE SERVER-SIDE SYSTEM-PROCS FROM 8.0 to SP1.
  6.  
  7. Changes in this file are organized as follows (please maintain):
  8.     System Tables (UPGRADE.SQL)
  9.     System Messages (MESSAGES.SQL / MSGWORK.SQL / SERVMSGS.SQL)
  10.     Engine System Procs (U_TABLES.SQL / PROCSYST.SQL / ODSOLE.SQL)
  11.     Schema Procs (OLEDBSCH.SQL / ANSIVIEW.SQL)
  12.     ODBC/OLEDB Catalog Procs (INSTCAT.SQL)
  13.     SEM SQLDMO System Procs (SQLDMO.SQL)
  14.  
  15. Changes to these scripts should NOT be placed in this file:
  16.     Starfighter Procs (XPSTAR.SQL / INSTMSDB.SQL / SQLTRACE.SQL / WEB.SQL)
  17.     Doc's Samples (INSTPUBS.SQL / INSTNWND.SQL)
  18.     Replication Procs (REPLSYS.SQL / REPLCOM.SQL / REPLTRAN.SQL / REPLMERG.SQL)
  19. These components will maintain separate upgrade scripts.
  20.  
  21. Notes:
  22. + Catalog-updates and sp_MS_upd_sysobj_category are enabled for the entire
  23.     file.  Do not disable or re-enable them.  Please do not change set options.
  24.  
  25. ------------------------------------------------------------------------------*/
  26.  
  27.  
  28. --------------------------------------------------------------------------------
  29. -- VERIFY Server is started in single-user-mode (catalog-updates enables), and
  30. --    start marking of system-objects.
  31. --------------------------------------------------------------------------------
  32. execute sp_configure 'allow updates',1
  33. go
  34.  
  35. reconfigure with override
  36. go
  37.  
  38. exec sp_MS_upd_sysobj_category 1
  39. go
  40.  
  41. --------------------------------------------------------------------------------
  42. --    System Tables (UPGRADE.SQL)
  43. --------------------------------------------------------------------------------
  44.  
  45. --------------------------------------------------------------------------------
  46. --    System Messages (MESSAGES.SQL / MSGWORK.SQL / SERVMSGS.SQL) English
  47. --------------------------------------------------------------------------------
  48. DELETE sysmessages
  49.     where error in
  50.     (15355, 21074, 21396
  51.     ,8668, 8669
  52.     ,13089, 13090, 13091
  53.     ,7619
  54.     ,1959, 15248
  55.     ,21513
  56.     ,21512
  57.     ,21515, 21516, 21517, 21518, 21519, 21520
  58.     ,14359
  59.     ,8526
  60. )
  61. go
  62.  
  63. -- 21396 has no corresponding new message.  It has been replaced with an updated 21074
  64.  
  65. insert into master..sysmessages (error ,severity ,dlevel ,description ,msglangid)
  66.     values
  67.     (15355 ,10 ,0 ,'''sys'' will be a reserved user or role name in next version of SQL Server.', 1033)
  68. insert into master..sysmessages (error, severity, dlevel, description, msglangid)
  69.     values
  70.     (21074,16,0, 'The subscription(s) have been marked inactive and must be reinitialized. NoSync subscriptions will need to be dropped and recreated.', 1033)
  71. go
  72.  
  73. insert into master..sysmessages (error ,severity ,dlevel ,description ,msglangid)
  74.     values
  75.     (8668,16 ,0 ,'An index cannot be created on the view ''%.*ls'' because the select list of the view contains a non-aggregate expression.' ,1033)
  76.  
  77. insert into master..sysmessages (error ,severity ,dlevel ,description ,msglangid)
  78.     values
  79.     (8669,16 ,0 ,'The indexed view ''%.*ls'' is not updatable.' ,1033)
  80.  
  81. insert into master..sysmessages (error ,severity ,dlevel ,description ,msglangid)
  82.     values
  83.     (13089 ,10 ,0 ,'lock' ,1033)
  84.  
  85. insert into master..sysmessages (error ,severity ,dlevel ,description ,msglangid)
  86.     values
  87.     (13090 ,10 ,0 ,'thread' ,1033)
  88.  
  89. insert into master..sysmessages (error ,severity ,dlevel ,description ,msglangid)
  90.     values
  91.     (13091 ,10 ,0 ,'communication buffer' ,1033)
  92. go
  93.  
  94. insert into master..sysmessages (error ,severity ,dlevel ,description ,msglangid) values
  95.         (7619, 16, 0, 'Execution of a full-text operation failed. %ls', 1033)
  96. go
  97.  
  98. insert into master..sysmessages (error ,severity ,dlevel ,description ,msglangid)
  99.     values
  100.     (1959, 16 ,0 ,'Cannot create an index on a view or computed column because the compatibility level of this database is less than 80.' ,1033)
  101. insert into master..sysmessages (error ,severity ,dlevel ,description ,msglangid)
  102.     values
  103.     (15248 ,11 ,0 ,'Either the parameter @objname is ambiguous or the claimed @objtype (%s) is wrong.' ,1033)
  104. go
  105.  
  106. insert into master..sysmessages (error, severity, dlevel, description, msglangid)
  107.     values
  108.     (21513,18,0,'Foreign key column ''%s'' cannot be excluded from a vertical partition.', 1033)
  109. go
  110.  
  111. insert into master..sysmessages (error, severity, dlevel, description, msglangid)
  112.     values
  113.     (21512,18,0,'%ls: The %ls parameter is shorter than the minimum required size.', 1033)
  114. GO
  115.  
  116. insert into master..sysmessages (error, severity, dlevel, description, msglangid)
  117.     values
  118.     (21515,18,0,'Replication custom procedures will not be scripted because the specified publication ''%s'' is a snapshot publication.', 1033)
  119.  
  120. insert into master..sysmessages (error, severity, dlevel, description, msglangid)
  121.     values
  122.     (21516,10,0,'Transactional replication custom procedures for publication ''%s'' from database ''%s'':', 1033)
  123.  
  124. insert into master..sysmessages (error, severity, dlevel, description, msglangid)
  125.     values
  126.     (21517,10,0,'Replication custom procedures will not be scripted for article ''%s'' because the auto-generate custom procedures schema option is not enabled.', 1033)
  127.  
  128. insert into master..sysmessages (error, severity, dlevel, description, msglangid)
  129.     values
  130.     (21518,0,0,'Replication custom procedures for article ''%s'':', 1033)
  131.  
  132. insert into master..sysmessages (error, severity, dlevel, description, msglangid)
  133.     values
  134.     (21519,10,0,'Custom procedures will not be scripted for article update commands based on direct INSERT, UPDATE, or DELETE statements.', 1033)
  135.  
  136. insert into master..sysmessages (error, severity, dlevel, description, msglangid)
  137.     values
  138.     (21520,10,0,'Custom procedure will not be scripted because ''%s'' is not a recognized article update command syntax.', 1033)
  139.  
  140. insert into master..sysmessages (error ,severity ,dlevel ,description ,msglangid)
  141.     values
  142.     (14359, 16, 0, 'Active Directory is either not enabled on the network or not supported by the operating system.', 1033)
  143. go
  144.  
  145. insert into master..sysmessages (error ,severity ,dlevel ,description ,msglangid)
  146.     values
  147.     (8526, 16, 0, 'Cannot go remote while the session is enlisted in a distributed transaction that has an active savepoint.', 1033)
  148. go
  149. --------------------------------------------------------------------------------
  150. --    System Messages (MESSAGES.SQL / MSGWORK.SQL / SERVMSGS.SQL) Localized
  151. --------------------------------------------------------------------------------
  152.  
  153.  
  154. --------------------------------------------------------------------------------
  155. --    Engine System Procs (U_TABLES.SQL / PROCSYST.SQL / ODSOLE.SQL)
  156. --------------------------------------------------------------------------------
  157. update spt_values 
  158.     set low = -2147483648 
  159.     where number = 1535 and type = 'C'
  160.  
  161. update spt_values 
  162.     set low = -2147483648 
  163.     where number = 1549 and type = 'C'
  164.  
  165. if object_id('sp_helptext','P') IS NOT NULL
  166.     drop procedure sp_helptext
  167. if object_id('sp_droplogin','P') IS NOT NULL
  168.     drop procedure sp_droplogin
  169. if object_id('sp_addsrvrolemember','P') IS NOT NULL
  170.     drop procedure sp_addsrvrolemember
  171. if object_id('sp_dropsrvrolemember','P') IS NOT NULL
  172.     drop procedure sp_dropsrvrolemember
  173. if object_id('sp_grantdbaccess','P') IS NOT NULL
  174.     drop procedure sp_grantdbaccess
  175. if object_id('sp_addalias','P') IS NOT NULL
  176.     drop procedure sp_addalias
  177. if object_id('sp_addrole','P') IS NOT NULL
  178.     drop procedure sp_addrole
  179. if object_id('sp_addapprole','P') IS NOT NULL
  180.     drop procedure sp_addapprole
  181. if object_id('sp_change_users_login','P') IS NOT NULL
  182.     drop procedure sp_change_users_login
  183. if object_id('sp_fulltext_table','P') IS NOT NULL
  184.     drop procedure sp_fulltext_table
  185. if object_id('sp_fulltext_column','P') IS NOT NULL
  186.     drop procedure sp_fulltext_column
  187. go
  188.  
  189. create procedure sp_droplogin
  190.     @loginame sysname
  191. as
  192.  
  193. declare @exec_stmt nvarchar(890)
  194.  
  195.     -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
  196.     set nocount on
  197.     declare    @sid    varbinary(85)
  198.  
  199.     /*Create temp tables before any DML to ensure dynamic*/
  200.     -- CREATE TEMPORARY TABLES FOR LATER USE --
  201.        create table #db_list (dbname sysname collate database_default not null, user_name sysname collate database_default not null)
  202.     create table #retval (job_count int not null)
  203.  
  204.     -- CHECK PERMISSIONS --
  205.     IF (not is_srvrolemember('securityadmin') = 1)
  206.     begin
  207.        dbcc auditevent (104, 2, 0, @loginame, NULL, NULL, NULL)
  208.        raiserror(15247,-1,-1)
  209.        return (1)
  210.     end
  211.     ELSE
  212.     begin
  213.        dbcc auditevent (104, 2, 1, @loginame, NULL, NULL, NULL)
  214.     end
  215.  
  216.     -- DISALLOW USER TRANSACTION --
  217.     set implicit_transactions off
  218.     IF (@@trancount > 0)
  219.     begin
  220.         raiserror(15002,-1,-1,'sp_droplogin')
  221.         return (1)
  222.     end
  223.  
  224.     -- VALIDATE LOGIN NAME (SQL LOGIN) --
  225.     select @sid = sid from master.dbo.syslogins
  226.         where loginname = @loginame and isntname = 0
  227.     if (@sid is null)
  228.     begin
  229.         raiserror(15007,10,-1,@loginame)
  230.         return(1)
  231.     end
  232.     -- CANNOT CHANGE SA ROLES --
  233.     else if @sid = 0x1    -- 'sa'
  234.     begin
  235.         raiserror(15405, -1 ,-1, @loginame)
  236.         return (1)
  237.     end
  238.  
  239.     -- CHECK IF @sid IS CURRENTLY LOGGED IN (ignore cached remote connections) --
  240.     if exists(select * from master.dbo.sysprocesses where sid = @sid and status != 'dormant')
  241.     begin
  242.         raiserror(15434, -1, -1, @loginame)
  243.         return(1)
  244.     end
  245.  
  246.     -- CHECK IF ANY DATABASES ARE OWNED BY LOGIN --
  247.     if exists(select * from master.dbo.sysdatabases where sid = @sid)
  248.     begin
  249.         raiserror(15174, -1, -1, @loginame)
  250.         select 'Databases owned by login:' = name
  251.                 from master.dbo.sysdatabases where sid = @sid
  252.         return(1)
  253.     end
  254.  
  255.     -- COLLECT ALL INSTANCES OF USE OF THIS LOGIN IN SYSUSERS --
  256.     declare @dbname        sysname
  257.     declare ms_crs_dbname cursor local keyset for select name from master.dbo.sysdatabases
  258.     open ms_crs_dbname
  259.     fetch ms_crs_dbname into @dbname
  260.     while @@fetch_status >= 0
  261.     begin
  262.         if (has_dbaccess(@dbname) = 1)
  263.         begin
  264.             select @exec_stmt = 'use ' + quotename( @dbname , '[') + '
  265.                    insert into #db_list (dbname, user_name)
  266.                 select N'+ quotename( @dbname , '''')+', name from sysusers
  267.                 where sid = suser_sid(N' + quotename( @loginame , '''') + ') '
  268.             exec (@exec_stmt)
  269.         end
  270.         else
  271.             raiserror(15622,-1,-1, @dbname)
  272.  
  273.         fetch ms_crs_dbname into @dbname
  274.     end
  275.     deallocate ms_crs_dbname
  276.  
  277.     -- ERROR IF LOGIN USED AS USER IN ANY DATABASE --
  278.     if (select count(*) from #db_list) <> 0
  279.     begin
  280.         raiserror(15175,-1,-1,@loginame)
  281.         select
  282.             'Database name:' = dbname,
  283.             'User name:' = user_name,
  284.             'Mapping type:' = 'user'
  285.         from #db_list
  286.         order by dbname
  287.         return (1)
  288.     end
  289.  
  290.     -- VERIFY NO JOBS IN MSDB OWNED BY THIS LOGIN --
  291.     if db_id('msdb') is not null
  292.         and object_id('msdb.dbo.sp_check_for_owned_jobs') is not null
  293.     begin
  294.         exec msdb.dbo.sp_check_for_owned_jobs @loginame, '#retval'
  295.         if exists (select job_count from #retval where job_count > 0)
  296.         begin
  297.             declare @job_count int
  298.             select @job_count = job_count from #retval
  299.             raiserror(14248, -1, -1, @job_count)
  300.             return (1)
  301.         end
  302.     end
  303.  
  304.     -- DELETE THIS LOGIN (ALSO DELETES REMOTE LOGINS MAPPED TO IT) --
  305.     delete from master.dbo.sysxlogins where sid = @sid
  306.  
  307.     -- FINALIZATION: SUCCESS/FAILURE MESSAGE
  308.     if @@rowcount > 0
  309.     begin
  310.         -- UPDATE PROTECTION TIMESTAMP FOR MASTER DB, TO INDICATE SYSLOGINS CHANGE --
  311.         exec('use master grant all to null')
  312.  
  313.         raiserror(15479,-1,-1)
  314.         return (0)
  315.     end
  316.     else
  317.     begin
  318.         raiserror(15007,10,-1,@loginame)
  319.         return (1)
  320.     end     -- sp_droplogin
  321. go
  322.  
  323. create procedure sp_addsrvrolemember
  324.     @loginame sysname,            -- login name
  325.     @rolename sysname = NULL    -- server role name
  326. as
  327.     -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
  328.     set nocount on
  329.     declare @ret        int,    -- return value of sp call
  330.             @rolebit    smallint,
  331.             @ismem      int,
  332.             @sid        varbinary(85)
  333.  
  334.     -- DISALLOW USER TRANSACTION --
  335.     set implicit_transactions off
  336.     IF (@@trancount > 0)
  337.     begin
  338.         raiserror(15002,-1,-1,'sp_addsrvrolemember')
  339.         return (1)
  340.     end
  341.  
  342.     -- VALIDATE SERVER ROLE NAME, CHECKING PERMISSIONS --
  343.     select @ismem = is_srvrolemember(@rolename)
  344.     if @ismem is null
  345.     begin
  346.         dbcc auditevent (108, 1, 0, @loginame, NULL, @rolename, NULL)
  347.         raiserror(15402, -1, -1, @rolename)
  348.         return (1)
  349.     end
  350.     if @ismem = 0
  351.     begin
  352.         dbcc auditevent (108, 1, 0, @loginame, NULL, @rolename, NULL)
  353.         raiserror(15247,-1,-1)
  354.         return (1)
  355.     end
  356.  
  357.     -- AUDIT A SUCCESSFUL SECURITY CHECK --
  358.     dbcc auditevent (108, 1, 1, @loginame, NULL, @rolename, NULL)
  359.  
  360.     -- OBTAIN THE BIT FOR THIS ROLE --
  361.     select @rolebit = CASE @rolename
  362.             WHEN 'sysadmin'         THEN 16
  363.             WHEN 'securityadmin'    THEN 32
  364.             WHEN 'serveradmin'      THEN 64
  365.             WHEN 'setupadmin'       THEN 128
  366.             WHEN 'processadmin'     THEN 256
  367.             WHEN 'diskadmin'        THEN 512
  368.             WHEN 'dbcreator'        THEN 1024
  369.             WHEN 'bulkadmin'        THEN 4096
  370.             ELSE NULL END
  371.  
  372.     select @sid = sid from master.dbo.syslogins where loginname = @loginame
  373.     -- ADD ROW FOR NT LOGIN IF NEEDED --
  374.     if @sid is null
  375.     begin
  376.         execute @ret = sp_MSaddlogin_implicit_ntlogin @loginame
  377.         if (@ret <> 0)
  378.         begin
  379.             raiserror(15007,-1,-1,@loginame)
  380.             return (1)
  381.         end
  382.     end
  383.     -- CANNOT CHANGE SA ROLES --
  384.     else if @sid = 0x1    -- 'sa'
  385.     begin
  386.         raiserror(15405, -1 ,-1, @loginame)
  387.         return (1)
  388.     end
  389.  
  390.     -- UPDATE ROLE MEMBERSHIP --
  391.     update master.dbo.sysxlogins set xstatus = xstatus | @rolebit, xdate2 = getdate()
  392.         where name = @loginame and srvid IS NULL
  393.  
  394.     -- UPDATE PROTECTION TIMESTAMP FOR MASTER DB, TO INDICATE SYSLOGINS CHANGE --
  395.     exec('use master grant all to null')
  396.  
  397.     raiserror(15488,-1,-1,@loginame,@rolename)
  398.  
  399.     -- FINALIZATION: RETURN SUCCESS/FAILURE
  400.     return (@@error) -- sp_addsrvrolemember
  401. go
  402.  
  403. create procedure sp_dropsrvrolemember
  404.     @loginame sysname,            -- login name
  405.     @rolename sysname = NULL    -- server role name
  406. as
  407.     -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
  408.     set nocount on
  409.     declare @ret        int,    -- return value of sp call
  410.             @rolebit    smallint,
  411.             @ismem      int,
  412.             @sid        varbinary(85)
  413.  
  414.     -- DISALLOW USER TRANSACTION --
  415.     set implicit_transactions off
  416.     IF (@@trancount > 0)
  417.     begin
  418.         raiserror(15002,-1,-1,'sp_dropsrvrolemember')
  419.         return (1)
  420.     end
  421.  
  422.     -- VALIDATE SERVER ROLE NAME, CHECKING PERMISSIONS --
  423.     select @ismem = is_srvrolemember(@rolename)
  424.     if @ismem is null
  425.     begin
  426.         dbcc auditevent (108, 2, 0, @loginame, NULL, @rolename, NULL)
  427.         raiserror(15402, -1, -1, @rolename)
  428.         return (1)
  429.     end
  430.     if @ismem = 0
  431.     begin
  432.         dbcc auditevent (108, 2, 0, @loginame, NULL, @rolename, NULL)
  433.         raiserror(15247,-1,-1)
  434.         return (1)
  435.     end
  436.  
  437.     -- AUDIT THE SUCCESSFUL SECURITY CHECK --
  438.     dbcc auditevent (108, 2, 1, @loginame, NULL, @rolename, NULL)
  439.  
  440.     -- OBTAIN THE BIT FOR THIS ROLE --
  441.     select @rolebit = CASE @rolename
  442.             WHEN 'sysadmin'         THEN 16
  443.             WHEN 'securityadmin'    THEN 32
  444.             WHEN 'serveradmin'      THEN 64
  445.             WHEN 'setupadmin'       THEN 128
  446.             WHEN 'processadmin'     THEN 256
  447.             WHEN 'diskadmin'        THEN 512
  448.             WHEN 'dbcreator'        THEN 1024
  449.             WHEN 'bulkadmin'        THEN 4096
  450.             ELSE NULL END
  451.  
  452.     select @sid = sid from master.dbo.syslogins where loginname = @loginame
  453.     -- ERROR IF USER DOESNT EXIST --
  454.     if @sid is null
  455.     begin
  456.         raiserror(15007,-1,-1,@loginame)
  457.         return (1)
  458.     end
  459.     -- CANNOT CHANGE SA ROLES --
  460.     else if @sid = 0x1    -- 'sa'
  461.     begin
  462.         raiserror(15405, -1 ,-1, @loginame)
  463.         return (1)
  464.     end
  465.  
  466.     -- UPDATE ROLE MEMBERSHIP --
  467.     update master.dbo.sysxlogins set xstatus = xstatus & ~@rolebit, xdate2 = getdate()
  468.         where name = @loginame and srvid IS NULL
  469.  
  470.     -- UPDATE PROTECTION TIMESTAMP FOR MASTER DB, TO INDICATE SYSLOGINS CHANGE --
  471.     exec('use master grant all to null')
  472.  
  473.     raiserror(15489,-1,-1,@loginame,@rolename)
  474.  
  475.     -- FINALIZATION: RETURN SUCCESS/FAILURE
  476.     return (@@error) -- sp_dropsrvrolemember
  477. go
  478.  
  479. create procedure sp_grantdbaccess
  480.     @loginame       sysname,
  481.     @name_in_db     sysname = NULL OUT
  482. as
  483.     -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
  484.     set nocount on
  485.     declare @ret        int,    -- return value of sp call
  486.             @uid        smallint,
  487.             @sid        varbinary(85),
  488.             @status     smallint
  489.  
  490.     if @name_in_db is null
  491.         select @name_in_db = @loginame
  492.  
  493.     -- CHECK PERMISSIONS --
  494.     if (not is_member('db_accessadmin') = 1) and
  495.        (not is_member('db_owner') = 1)
  496.     begin
  497.         dbcc auditevent (109, 3, 0, @loginame, @name_in_db, NULL, NULL)
  498.         raiserror(15247,-1,-1)
  499.         return (1)
  500.     end
  501.     else
  502.     begin
  503.         dbcc auditevent (109, 3, 1, @loginame, @name_in_db, NULL, NULL)
  504.     end
  505.  
  506.     -- DISALLOW USER TRANSACTION --
  507.     set implicit_transactions off
  508.     IF (@@trancount > 0)
  509.     begin
  510.         raiserror(15002,-1,-1,'sp_grantdbaccess')
  511.         return (1)
  512.     end
  513.  
  514.     -- VALIDATE NAME-IN-DB --
  515.     if @name_in_db <> @loginame
  516.     begin
  517.         exec @ret = sp_validname @name_in_db
  518.         if @ret <> 0
  519.             return(1)
  520.         if (charindex('\', @name_in_db) > 0)
  521.         begin
  522.             raiserror(15006,-1,-1,@name_in_db)
  523.             return (1)
  524.         end
  525.     end
  526.  
  527.     -- CHECK FOR SPECIAL USER GUEST --
  528.     if @name_in_db = 'guest'
  529.     begin
  530.         -- ERROR IF NOT USER, OR ALREADY ADDED --
  531.         if @loginame <> 'guest'
  532.         begin
  533.             raiserror(15062,-1,-1)
  534.             return(1)
  535.         end
  536.         if exists (select * from sysusers where hasdbaccess = 1 and name = 'guest')
  537.         begin
  538.             raiserror(15023,-1,-1,'guest')
  539.             return (1)
  540.         end
  541.  
  542.         -- ENABLE USER GUEST --
  543.         update sysusers set status = (status & ~1) | 2, updatedate = getdate()
  544.                     where name = 'guest'
  545.         return (0)
  546.     end
  547.  
  548.     -- VALIDATE LOGIN NAME (OBTAIN SID) --
  549.     select @status = case when (charindex('\', @loginame) <> 0) then 4 else 0 end
  550.     if @status = 0
  551.         select @sid = sid from master.dbo.syslogins         -- sql user
  552.             where isntname = 0 and loginname = @loginame
  553.     if @sid is null
  554.     begin
  555.         -- NT GROUPS REQUIRE DOMAIN NAME --
  556.         if @status = 4
  557.             select @sid = get_sid('\G'+@loginame, NULL)     -- nt group
  558.         if @sid is null
  559.         begin
  560.             select @sid = get_sid('\U'+@loginame, NULL)     -- nt user
  561.             if @sid is not null
  562.                 select @status = 12
  563.         end
  564.     end
  565.     -- PREVENT USE OF CERTAIN LOGINS --
  566.     else if @sid = 0x1    -- 'sa'
  567.     begin
  568.         raiserror(15405, -1, -1, @loginame)
  569.         return (1)
  570.     end
  571.  
  572.     if @sid is null
  573.     begin
  574.         if @status = 0
  575.             raiserror(15007,-1,-1,@loginame)
  576.         else
  577.             raiserror(15401,-1,-1,@loginame)
  578.         return (1)
  579.     end
  580.  
  581.     -- CHECK IF LOGIN ALREADY IN DATABASE --
  582.     if exists (select sid from sysusers where sid = @sid)
  583.     begin
  584.         -- ERROR IF LOGIN IS ALREADY ALIASED --
  585.         if exists (select sid from sysusers where sid = @sid and isaliased = 1)
  586.         begin
  587.             raiserror(15022,-1,-1)
  588.             return (1)
  589.         end
  590.  
  591.         -- ERROR IF ALREADY EXISTS UNDER DIFFERENT NAME --
  592.         if (not user_sid(user_id(@name_in_db)) = @sid)
  593.         begin
  594.             raiserror(15063,-1,-1)
  595.             return (1)
  596.         end
  597.  
  598.         -- ERROR IF LOGIN ALREADY HAS ACCESS --
  599.         if exists (select sid from sysusers where sid = @sid and hasdbaccess = 1)
  600.         begin
  601.             if @status = 4
  602.                 raiserror(15024,-1,-1,@name_in_db)
  603.             else
  604.                 raiserror(15023,-1,-1,@name_in_db)
  605.             return (1)
  606.         end
  607.  
  608.         -- GIVE DATABASE ACCESS TO THIS LOGIN --
  609.         update sysusers set status = (status & ~1) | 2, updatedate = getdate()
  610.                     where sid = @sid
  611.         return @@error
  612.     end
  613.  
  614.     if @name_in_db = 'sys'
  615.         raiserror(15355,-1,-1)
  616.  
  617.     if user_id(@name_in_db) is not null OR
  618.         @name_in_db IN ('system_function_schema','INFORMATION_SCHEMA')
  619.     begin
  620.         -- SYSUSERS NAME ALREADY EXISTS --
  621.         if @status = 4
  622.             raiserror(15024,-1,-1,@name_in_db)
  623.         else
  624.             raiserror(15023,-1,-1,@name_in_db)
  625.         return (1)
  626.     end
  627.  
  628.     -- OBTAIN NEW UID (RESERVE 1-4) --
  629.     if user_name(5) IS NULL
  630.         select @uid = 5
  631.     else
  632.         select @uid = min(uid)+1 from sysusers
  633.             where uid >= 5 and uid < (16384 - 1)    -- stay in users range
  634.                 and user_name(uid+1) is null        -- uid not in use
  635.     if @uid is null
  636.     begin
  637.         raiserror(15065,-1,-1)
  638.         return (1)
  639.     end
  640.  
  641.     -- INSERT SYSUSERS ROW --
  642.     insert into sysusers select
  643.         @uid, @status | 2, @name_in_db, @sid, 0x00, getdate(), getdate(), 0, NULL
  644.  
  645.     -- INVALIDATE CACHED PERMISSIONS --
  646.     grant all to null
  647.  
  648.     -- PRINT SUCCESS --
  649.     raiserror(15341,-1,-1, @loginame)
  650.  
  651.     -- RETURN SUCCESS STATUS --
  652.     return @@error -- sp_grantdbaccess
  653. go
  654.  
  655. create procedure sp_addalias
  656.     @loginame       sysname,    -- name of the pretender
  657.     @name_in_db     sysname     -- user to whom to alias the login
  658. as
  659.     -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
  660.     set nocount on
  661.     declare @sid        varbinary(85),
  662.             @targuid    smallint,
  663.             @newuid     smallint,
  664.             @status     smallint,
  665.             @dbname     sysname
  666.  
  667.     -- CHECK PERMISSIONS --
  668.     if (not is_member('db_accessadmin') = 1) and
  669.        (not is_member('db_owner') = 1)
  670.     begin
  671.         raiserror(15247,-1,-1)
  672.         return (1)
  673.     end
  674.  
  675.     -- DISALLOW USER TRANSACTION --
  676.     set implicit_transactions off
  677.     IF (@@trancount > 0)
  678.     begin
  679.         raiserror(15002,-1,-1,'sp_addalias')
  680.         return (1)
  681.     end
  682.  
  683.     -- VALIDATE LOGIN NAME (OBTAIN SID) --
  684.     select @status = CASE WHEN charindex('\', @loginame) > 0 THEN 12 ELSE 0 END
  685.     if @status = 0
  686.         select @sid = suser_sid(@loginame)          -- sql user
  687.     -- retry sql user as nt with dflt domain
  688.     if @sid is null
  689.     begin
  690.         select @sid = get_sid('\U'+@loginame, NULL) -- nt user
  691.         if @sid is null
  692.         begin
  693.             if @status = 0
  694.                 raiserror(15007,-1,-1,@loginame)
  695.             else
  696.                 raiserror(15401,-1,-1,@loginame)
  697.             return (1)
  698.         end
  699.         select @status = 12
  700.     end
  701.     -- PREVENT USE OF CERTAIN LOGINS --
  702.     else if @sid = 0x1
  703.     begin
  704.         raiserror(15405, -1, -1, @loginame)
  705.         return (1)
  706.     end
  707.  
  708.     -- VALIDATE NAME-IN-DB (OBTAIN TARGET UID) --
  709.     select @targuid = uid from sysusers where name = @name_in_db
  710.                         and (issqluser = 1 or isntuser = 1)
  711.                         and uid NOT IN (3,4)    -- INFORMATION_SCHEMA, system_function_schema
  712.     if @targuid is null
  713.     begin
  714.         raiserror(15008,-1,-1,@name_in_db)
  715.         return (1)
  716.     end
  717.  
  718.     -- ERROR IF LOGIN ALREADY IN DATABASE --
  719.     if exists (select sid from sysusers where sid = @sid)
  720.     begin
  721.  
  722.         -- ERROR IF ALREADY ALIASED --
  723.         if exists (select sid from sysusers where sid = @sid and isaliased = 1)
  724.         begin
  725.             raiserror(15022,-1,-1)
  726.             return (1)
  727.         end
  728.  
  729.         -- ERROR: LOGIN ALREADY A USER --
  730.         select @name_in_db = name, @dbname = db_name() from sysusers where sid = @sid
  731.         raiserror(15278,-1,-1,@loginame,@name_in_db,@dbname)
  732.         return (1)
  733.     end
  734.  
  735.     -- ALTER NAME TO AVOID CONFLICTS IN NAME SPACE --
  736.     select @loginame = '\' + @loginame
  737.     if user_id(@loginame) is not null
  738.     begin
  739.         raiserror(15023,-1,-1,@loginame)
  740.         return (1)
  741.     end
  742.  
  743.     -- OBTAIN NEW UID (RESERVE 1-4) --
  744.     if user_name(5) IS NULL
  745.         select @newuid = 5
  746.     else
  747.         select @newuid = min(uid)+1 from sysusers
  748.             where uid >= 5 and uid < (16384 - 1)    -- stay in users range
  749.                 and user_name(uid+1) is null        -- uid not in use
  750.     if @newuid is null
  751.     begin
  752.         raiserror(15065,-1,-1)
  753.         return (1)
  754.     end
  755.  
  756.     -- INSERT SYSUSERS ROW --
  757.     insert into sysusers select
  758.         @newuid, @status | 16, @loginame, @sid, 0x00,
  759.                 getdate(), getdate(), @targuid, NULL
  760.  
  761.     -- FINALIZATION: PRINT/RETURN SUCCESS --
  762.     if @@error <> 0
  763.         return (1)
  764.     raiserror(15340,-1,-1)
  765.     return (0) -- sp_addalias
  766. go
  767.  
  768. create procedure sp_addrole
  769.     @rolename   sysname,        -- name of new role
  770.     @ownername  sysname = 'dbo' -- name of owner of new role
  771. as
  772.     -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
  773.     set nocount on
  774.     declare @ret        int,    -- return value of sp call
  775.             @uid        smallint,
  776.             @owner      smallint
  777.  
  778.     -- CHECK PERMISSIONS --
  779.     if (not is_member('db_securityadmin') = 1) and
  780.        (not is_member('db_owner') = 1)
  781.     begin
  782.         dbcc auditevent (111, 1, 0, NULL, NULL, @rolename, NULL)
  783.         raiserror(15247,-1,-1)
  784.         return (1)
  785.     end
  786.     else
  787.     begin
  788.         dbcc auditevent (111, 1, 1, NULL, NULL, @rolename, NULL)
  789.     end
  790.  
  791.     -- DISALLOW USER TRANSACTION --
  792.     set implicit_transactions off
  793.     if (@@trancount > 0)
  794.     begin
  795.         raiserror(15002,-1,-1,'sp_addrole')
  796.         return (1)
  797.     end
  798.  
  799.         -- RESOLVE OWNER NAME --
  800.     select @owner = uid from sysusers where name = @ownername
  801.                     and isaliased = 0 AND uid NOT IN (0,3,4) --public/INFO_SCHEMA/etc can't own role
  802.     if @owner is null
  803.     begin
  804.         raiserror(15008,-1,-1,@ownername)
  805.         return (1)
  806.     end
  807.  
  808.     -- VALIDATE ROLE NAME --
  809.     execute @ret = sp_validname @rolename
  810.     if @ret <> 0
  811.         return (1)
  812.     if (charindex('\', @rolename) > 0)
  813.     begin
  814.         raiserror(15006,-1,-1,@rolename)
  815.         return (1)
  816.     end
  817.  
  818.     if @rolename = 'sys'
  819.         raiserror(15355,-1,-1)
  820.  
  821.     -- ERROR IF SYSUSERS NAME ALREADY EXISTS --
  822.     if user_id(@rolename) is not null OR
  823.         @rolename IN ('system_function_schema','INFORMATION_SCHEMA')
  824.     begin
  825.         if exists (select name from sysusers where issqlrole = 1 and name = @rolename)
  826.             raiserror(15363,-1,-1,@rolename)
  827.         else
  828.             raiserror(15023,-1,-1,@rolename)
  829.  
  830.         return (1)
  831.     end
  832.  
  833.     -- OBTAIN NEW ROLE UID (RESERVE 16384-16399) --
  834.     if user_name(16400) IS NULL
  835.         select @uid = 16400
  836.     else
  837.         select @uid = min(uid)+1 from sysusers
  838.             where uid >= 16400 and uid < (32767 - 1)    -- stay in role range
  839.                 and user_name(uid+1) is null            -- uid not in use
  840.     if @uid is null
  841.     begin
  842.         raiserror(15065,-1,-1)
  843.         return (1)
  844.     end
  845.  
  846.     -- INSERT THE ROW INTO SYSUSERS --
  847.     insert into sysusers values
  848.         (@uid, 0, @rolename, NULL, 0x00, getdate(), getdate(), @owner, NULL)
  849.  
  850.     -- FINALIZATION: PRINT/RETURN SUCCESS --
  851.     if @@error <> 0
  852.         return (1)
  853.     raiserror(15424,-1,-1)
  854.     return (0) -- sp_addrole
  855. go
  856.  
  857. create procedure sp_addapprole
  858.     @rolename   sysname,        -- name of new app role
  859.     @password   sysname         -- password for app role
  860. as
  861.     -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
  862.     set nocount on
  863.     declare @ret        int,    -- return value of sp call
  864.             @uid        smallint
  865.  
  866.     -- CHECK FOR NULL PASSWORD
  867.     if (@password is null)
  868.     begin
  869.         raiserror(15034,-1,-1)
  870.         return (1)
  871.     end
  872.  
  873.     -- CHECK PERMISSIONS --
  874.     if (not is_member('db_securityadmin') = 1) and
  875.        (not is_member('db_owner') = 1)
  876.     begin
  877.         raiserror(15247,-1,-1)
  878.         return (1)
  879.     end
  880.  
  881.     -- DISALLOW USER TRANSACTION --
  882.     set implicit_transactions off
  883.     if (@@trancount > 0)
  884.     begin
  885.         raiserror(15002,-1,-1,'sp_addapprole')
  886.         return (1)
  887.     end
  888.  
  889.     -- VALIDATE APPROLE NAME --
  890.     execute @ret = sp_validname @rolename
  891.     if @ret <> 0
  892.         return (1)
  893.     if (charindex('\', @rolename) > 0)
  894.     begin
  895.         raiserror(15006,-1,-1,@rolename)
  896.         return (1)
  897.     end
  898.  
  899.     if @rolename = 'sys'
  900.         raiserror(15355,-1,-1)
  901.  
  902.     -- ERROR IF SYSUSERS NAME ALREADY EXISTS --
  903.     if user_id(@rolename) is not null OR
  904.         @rolename IN ('system_function_schema','INFORMATION_SCHEMA')
  905.     begin
  906.         raiserror(15363,-1,-1,@rolename)
  907.         return (1)
  908.     end
  909.  
  910.     -- OBTAIN NEW APPROLE UID (RESERVE 1-4) --
  911.     if user_name(5) IS NULL
  912.         select @uid = 5
  913.     else
  914.         select @uid = min(uid)+1 from sysusers
  915.             where uid >= 5 and uid < (16384 - 1)    -- stay in users range
  916.                 and user_name(uid+1) is null        -- uid not in use
  917.     if @uid is null
  918.     begin
  919.         raiserror(15065,-1,-1)
  920.         return (1)
  921.     end
  922.  
  923.     -- INSERT THE ROW INTO SYSUSERS --
  924.     insert into sysusers values
  925.         (@uid, 32, @rolename, NULL, 0x00, getdate(),
  926.                     getdate(), 1, convert(varbinary(256), pwdencrypt(@password)))
  927.  
  928.     -- FINALIZATION: PRINT/RETURN SUCCESS --
  929.     if @@error <> 0
  930.         return (1)
  931.     raiserror(15425,-1,-1)
  932.     return (0) -- sp_addapprole
  933. go
  934.  
  935. CREATE PROCEDURE sp_change_users_login
  936.     @Action               varchar(10)       -- REPORT / UPDATE_ONE / AUTO_FIX
  937.    ,@UserNamePattern      sysname  = Null
  938.    ,@LoginName            sysname  = Null
  939. AS
  940.     -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
  941.     set nocount on
  942.     declare @exec_stmt nvarchar(430)
  943.  
  944.     declare @ret            int,
  945.             @FixMode        char(5),
  946.             @cfixesupdate   int,        -- count of fixes by update
  947.             @cfixesaddlogin int,        -- count of fixes by sp_addlogin
  948.             @dbname         sysname,
  949.             @loginsid       varbinary(85),
  950.             @110name        sysname
  951.  
  952.     -- SET INITIAL VALUES --
  953.     select  @dbname         = db_name(),
  954.             @cfixesupdate   = 0,
  955.             @cfixesaddlogin = 0
  956.  
  957.     -- ERROR IF IN USER TRANSACTION --
  958.     if @@trancount > 0
  959.     begin
  960.         raiserror(15289,-1,-1)
  961.         return (1)
  962.     end
  963.  
  964.     -- INVALIDATE USE OF SPECIAL LOGIN/USER NAMES --
  965.     if suser_sid(@LoginName) = 0x1    -- 'sa'
  966.     begin
  967.         raiserror(15287,-1,-1,@LoginName)
  968.         return (1)
  969.     end
  970.     if user_id(@UserNamePattern) in (1,0,3,4) --dbo, public, INFORMATION_SCHEMA, system_function_schema
  971.     begin
  972.         raiserror(15287,-1,-1,@UserNamePattern)
  973.         return (1)
  974.     end
  975.  
  976.     -- HANDLE REPORT --
  977.     if upper(@Action) = 'REPORT'
  978.     begin
  979.  
  980.         -- VALIDATE PARAMS --
  981.         if @UserNamePattern IS NOT Null or @LoginName IS NOT Null
  982.         begin
  983.             raiserror(15290,-1,-1,@Action,@UserNamePattern,@LoginName)
  984.             return (1)
  985.         end
  986.  
  987.         -- GENERATE REPORT --
  988.         select UserName = name, UserSID = sid from sysusers
  989.             where issqluser = 1 and (sid is not null and sid <> 0x0)
  990.                     and suser_sname(sid) is null
  991.             order by name
  992.         return (0)
  993.     end
  994.  
  995.     -- HANDLE UPDATE_ONE --
  996.     if upper(@Action) = 'UPDATE_ONE'
  997.     begin
  998.  
  999.         -- CHECK PERMISSIONS --
  1000.         if not is_member('db_owner') = 1
  1001.         begin
  1002.             raiserror(15247,-1,-1)
  1003.             return (1)
  1004.         end
  1005.  
  1006.         -- ERROR IF PARAMS NULL --
  1007.         if @UserNamePattern IS Null or @LoginName IS Null
  1008.         begin
  1009.             raiserror(15290,-1,-1,@Action,@UserNamePattern,@LoginName)
  1010.             return (1)
  1011.         end
  1012.  
  1013.         -- VALIDATE PARAMS --
  1014.         -- Can ONLY remap SQL Users to SQL Logins!  Should be no need
  1015.         --  for re-mapping NT logins, and if you try, you'll mess up
  1016.         --  the user status bits! 
  1017.         if not exists (select name from sysusers where
  1018.                 name = @UserNamePattern             -- match user name
  1019.             and issqluser = 1)                      -- must be sql user
  1020.         begin
  1021.             raiserror(15291,-1,-1,'User',@UserNamePattern)
  1022.             return (1)
  1023.         end
  1024.         select @loginsid = sid from master.dbo.syslogins where
  1025.                 loginname = @LoginName              -- match login name
  1026.             and isntname = 0                        -- cannot use nt logins
  1027.         if @loginsid is null
  1028.         begin
  1029.             raiserror(15291,-1,-1,'Login',@LoginName)
  1030.             return (1)
  1031.         end
  1032.  
  1033.         -- ERROR IF SID ALREADY IN USE IN DATABASE --
  1034.         if exists (select sid from sysusers where sid = @loginsid
  1035.                     and name <> @UserNamePattern)
  1036.         begin
  1037.             raiserror(15063,-1,-1)
  1038.             return (1)
  1039.         end
  1040.  
  1041.         -- CHANGE THE USERS LOGIN (SID) --
  1042.         update sysusers set sid = @loginsid, updatedate = getdate()
  1043.                 where name = @UserNamePattern and issqluser = 1
  1044.                 and sid <> @loginsid
  1045.  
  1046.         -- FINALIZATION: REPORT (ONLY IF NOT SUCCESSFUL) AND EXIT --
  1047.         if @@error <> 0 or @@rowcount <> 1
  1048.             raiserror(15295,-1,-1, 0)
  1049.         return (0)
  1050.     end
  1051.  
  1052.     -- ERROR IF NOT AUTO_FIX --
  1053.     if upper(@Action) <> 'AUTO_FIX'
  1054.     begin
  1055.         raiserror(15286,-1,-1,@Action)
  1056.         return (1)
  1057.     end
  1058.  
  1059.     -- HANDLE AUTO_FIX --
  1060.     -- CHECK PERMISSIONS --
  1061.     if not is_srvrolemember('sysadmin') = 1
  1062.     begin
  1063.         raiserror(15247,-1,-1)
  1064.         return (1)
  1065.     end
  1066.  
  1067.     -- VALIDATE PARAMS --
  1068.     if @UserNamePattern IS Null or @LoginName IS NOT Null
  1069.     begin
  1070.         raiserror(15290,-1,-1,@Action,@UserNamePattern,@LoginName)
  1071.         return (1)
  1072.     end
  1073.  
  1074.     -- LOOP THRU ORPHANED USERS --
  1075.     select @exec_stmt = 'DECLARE ms_crs_110_Users cursor global for
  1076.             select name from sysusers
  1077.             where name = N' + quotename( @UserNamePattern , '''')+ '
  1078.                 and issqluser = 1 and suser_sname(sid) is null'
  1079.     EXECUTE (@exec_stmt)
  1080.     OPEN ms_crs_110_Users
  1081.  
  1082.     WHILE (110=110)
  1083.     begin
  1084.         FETCH next from ms_crs_110_Users into @110name
  1085.         if (@@fetch_status <> 0)
  1086.         begin
  1087.             DEALLOCATE ms_crs_110_Users
  1088.             BREAK
  1089.         end
  1090.  
  1091.         -- IS NAME ALREADY IN USE? --
  1092.         -- if suser_sid(@110name) is null
  1093.         if not exists(select * from master.dbo.syslogins where loginname = @110name)
  1094.         begin
  1095.  
  1096.             -- ADD LOGIN --
  1097.             execute @ret = sp_addlogin @110name, Null, @dbname
  1098.             if @ret <> 0 or suser_sid(@110name) is null
  1099.             begin
  1100.                 raiserror(15497,16,1,@110name)
  1101.                 deallocate ms_crs_110_Users
  1102.                 return (1)
  1103.             end
  1104.             select @FixMode = '1AddL'
  1105.             raiserror(15293,-1,-1,@110name)
  1106.         end
  1107.         ELSE
  1108.         begin
  1109.             Select @FixMode = '2UpdU'
  1110.             Raiserror(15292,-1,-1,@110name)
  1111.         end
  1112.  
  1113.         -- REPORT ERROR & CONTINUE IF DUPLICATE SID IN DB --
  1114.         select @loginsid = suser_sid(@110name)
  1115.         if user_sid(@loginsid) is not null
  1116.         begin
  1117.             raiserror(15331,-1,-1,@110name)
  1118.             CONTINUE
  1119.         end
  1120.  
  1121.         -- UPDATE SYSUSERS ROW --
  1122.         update sysusers set sid = @loginsid, updatedate = getdate() where name = @110name
  1123.         if @@error <> 0
  1124.         begin
  1125.             raiserror(15498,17,127)
  1126.             deallocate ms_crs_110_Users
  1127.             return (1)
  1128.         end
  1129.  
  1130.  
  1131.         if @FixMode = '1AddL'
  1132.             Select @cfixesaddlogin = @cfixesaddlogin + 1
  1133.         else
  1134.             Select @cfixesupdate = @cfixesupdate + 1
  1135.     end -- loop 110
  1136.  
  1137.     -- REPORT AND RETURN SUCCESS --
  1138.     raiserror(15295,-1,-1,@cfixesupdate)
  1139.     raiserror(15294,-1,-1,@cfixesaddlogin)
  1140.     return (0) -- sp_change_users_login
  1141. go
  1142.  
  1143. create proc sp_fulltext_table
  1144.     @tabname    nvarchar(517),
  1145.     @action        varchar(50),
  1146.     @ftcat        sysname = NULL,        -- create: catalog name
  1147.     @keyname    sysname = NULL        -- create: name of unique index
  1148. as
  1149.     declare @schemamodified int
  1150.     -- FULLTEXT MUST BE ACTIVE IN DATABASE --
  1151.     if DatabaseProperty(db_name(), 'IsFulltextEnabled') = 0
  1152.     begin
  1153.         raiserror(15601,-1,-1)
  1154.         return 1
  1155.     end
  1156.  
  1157.     -- VALIDATE PARAMS --
  1158.     if @action is null
  1159.         OR @action not in ('create','drop','activate','deactivate',
  1160.             'start_change_tracking', 'stop_change_tracking',
  1161.             'start_background_updateindex', 'stop_background_updateindex',
  1162.             'update_index', 'start_full', 'start_incremental', 'stop')
  1163.         OR (@action not in ('create') and (@ftcat is not null or @keyname is not null))
  1164.         OR (@action in ('create') and (@ftcat is null or @keyname is null))
  1165.     begin
  1166.         raiserror(15600,-1,-1,'sp_fulltext_table')
  1167.         return 1
  1168.     end
  1169.  
  1170.     -- DISALLOW USER TRANSACTION --
  1171.     set implicit_transactions off
  1172.     if @@trancount > 0
  1173.     begin
  1174.         raiserror(15002,-1,-1,'sp_fulltext_table')
  1175.         return 1
  1176.     end
  1177.  
  1178.     -- VALIDATE TABLE NAME --
  1179.     --  (1) Must exist in current database
  1180.     declare @objid int
  1181.     select @objid = object_id(@tabname, 'local')
  1182.     if @objid is null
  1183.     begin
  1184.         declare @curdbname sysname
  1185.         select @curdbname = db_name()
  1186.         raiserror(15009,-1,-1 ,@tabname, @curdbname)
  1187.         return 1
  1188.     end
  1189.     --  (2) Must be a user table (and not a temp table)
  1190.     if ObjectProperty(@objid, 'IsUserTable') = 0 OR substring(parsename(@tabname,1),1,1) = '#'
  1191.     begin
  1192.         raiserror(15218,-1,-1 ,@tabname)
  1193.         return 1
  1194.     end
  1195.  
  1196.     -- CHECK PERMISSION ON TABLE --
  1197.     if (is_member('db_owner') = 0) AND (is_member('db_ddladmin') = 0)
  1198.         AND (is_member(user_name(ObjectProperty(@objid, 'ownerid'))) = 0)
  1199.     begin
  1200.         raiserror(15247,-1,-1)
  1201.         return 1
  1202.     end
  1203.  
  1204.     -- CHECK DATABASE MODE (must not be read-only) --
  1205.     if DATABASEPROPERTY(db_name(), 'IsReadOnly') = 1
  1206.     begin
  1207.         raiserror(15635, -1, -1, 'sp_fulltext_table')
  1208.         return 1
  1209.     end
  1210.  
  1211.     -- BEGIN TRAN AND LOCK TABLE --
  1212.     begin tran
  1213.     dbcc lockobjectschema(@tabname)
  1214.     if @@error <> 0
  1215.     begin
  1216.         goto error_abort_exit
  1217.     end
  1218.  
  1219.     -- OBTAIN CATALOG NAME FROM SYSOBJECTS & CHECK ACTION --
  1220.     declare @ftcatid smallint
  1221.     select @ftcatid = ObjectProperty(@objid, 'TableFulltextCatalogId')
  1222.     if @ftcatid <> 0 and @action = 'create'
  1223.     begin
  1224.         raiserror(15605,-1,-1,@tabname)
  1225.         goto error_abort_exit
  1226.     end
  1227.     if @ftcatid = 0 and @action <> 'create'
  1228.     begin
  1229.         raiserror(15606,-1,-1,@tabname)
  1230.         goto error_abort_exit
  1231.     end
  1232.  
  1233.     if @action = 'create'
  1234.     begin
  1235.         -- CHECK CATALOG NAME --
  1236.         select @ftcatid = null
  1237.         select @ftcatid = ftcatid from sysfulltextcatalogs where name = @ftcat
  1238.         if @ftcatid is null
  1239.         begin
  1240.             raiserror(7641,-1,-1,@ftcat)
  1241.             goto error_abort_exit
  1242.         end
  1243.  
  1244.         -- CHECK INDEX NAME (UNIQUE, SINGLE-KEY, 450-byte MAX, NON-NULLABLE) AND SET BIT IF FOUND --
  1245.         if IndexProperty(@objid, @keyname, 'IsUnique') = 1 and
  1246.            IndexProperty(@objid, @keyname, 'UserKeyCount') = 1 and
  1247.            IndexProperty(@objid, @keyname, 'IsHypothetical') = 0 and
  1248.            exists (select * from syscolumns where id = @objid and name = Index_col(@tabname, IndexProperty(@objid, @keyname, 'IndexId'), 1)
  1249.                 and length <= 450 and isnullable = 0)
  1250.         begin
  1251.             update sysindexes set status = status | 33554432 where id = @objid
  1252.                 and name = @keyname and indid > 0 and indid < 255
  1253.         end
  1254.         else
  1255.         begin
  1256.             raiserror(15607,-1,-1,@keyname)
  1257.             goto error_abort_exit
  1258.         end
  1259.  
  1260.         -- ADD CATALOG NAME TO SYSOBJECTS --
  1261.         update sysobjects set ftcatid = @ftcatid where id = @objid
  1262.  
  1263.         -- ADD TO CATALOG
  1264.         DBCC CALLFULLTEXT ( 5, @ftcatid, @objid )    -- FTAddURL( @ftcatid, db_id(), @objid )
  1265.         if @@error <> 0
  1266.             goto error_abort_exit
  1267.  
  1268.     end
  1269.  
  1270.     if @action = 'drop'
  1271.     begin
  1272.         -- DROP FROM CATALOG (NO ERROR IF ALREADY DROPPED) --
  1273.         DBCC CALLFULLTEXT ( 6, @ftcatid, @objid )    -- FTDropURL( @ftcatid, db_id(), @objid )
  1274.         if @@error <> 0
  1275.             goto error_abort_exit
  1276.  
  1277.         -- DELETE SYSDEPENDS ENTRIES FOR IMAGE COLUMNS, IF ANY --
  1278.         delete sysdepends where [id] = @objid and
  1279.                           depid = @objid and
  1280.                           deptype = 1 and
  1281.                           number in ( select colid from syscolumns where [id] = @objid and
  1282.                                                                          type = 34 and
  1283.                                                                          (colstat & 16) = 16 )
  1284.  
  1285.         -- REMOVE CATALOG NAME AND BITS FROM SYSTEM TABLES --
  1286.         update syscolumns set colstat = colstat & ~80, language = 0 where [id] = @objid
  1287.         update sysindexes set status = status & ~33554432 where [id] = @objid
  1288.         update sysobjects set status = status & ~200, ftcatid = 0 where [id] = @objid
  1289.  
  1290.         -- DELETE NOTIFICATIONS FROM SYSFULLTEXTNOTIFY --
  1291.         delete sysfulltextnotify where tableid = @objid
  1292.  
  1293.     end
  1294.  
  1295.     if @action = 'activate'
  1296.     begin
  1297.  
  1298.         -- MUST HAVE AT LEAST ONE COLUMN MARKED FOR FULLTEXT INDEXING --
  1299.         if not exists (select * from syscolumns where id = @objid and (colstat & 16) = 16)
  1300.         begin
  1301.             raiserror(15609, -1,-1,@tabname)
  1302.             goto error_abort_exit
  1303.         end
  1304.  
  1305.         -- NO ERROR IF INDEXING ALREADY ACTIVATED --
  1306.         if ObjectProperty(@objid, 'TableHasActiveFulltextIndex') = 1
  1307.         begin
  1308.             rollback tran
  1309.             return 0
  1310.         end
  1311.  
  1312.  
  1313.         update sysobjects set status = status | 8 where id = @objid
  1314.  
  1315.         if (ObjectProperty(@objid, 'TableFulltextChangeTrackingOn') = 1)
  1316.         begin
  1317.  
  1318.             -- STOP A FULL/INCREMENTAL POPULATION FOR THIS TABLE --
  1319.             DBCC CALLFULLTEXT ( 12, @ftcatid, @objid, 2 )
  1320.             if @@error <> 0
  1321.                 goto error_abort_exit
  1322.  
  1323.             -- DELETE SYSFULLTEXTNOTIFY ENTRIES
  1324.             delete sysfulltextnotify where tableid = @objid
  1325.  
  1326.             -- START A FULL CRAWL FOR THE TABLE
  1327.             DBCC CALLFULLTEXT ( 12, @ftcatid, @objid, 0 )
  1328.             if @@error <> 0
  1329.                 goto error_abort_exit
  1330.  
  1331.         end
  1332.  
  1333.  
  1334.     end
  1335.  
  1336.     if @action = 'deactivate'
  1337.     begin
  1338.         -- NO ERROR IF INDEXING ALREADY DEACTIVATED --
  1339.         if ObjectProperty(@objid, 'TableHasActiveFulltextIndex') = 0
  1340.         begin
  1341.             rollback tran
  1342.             return 0
  1343.         end
  1344.  
  1345.         -- IF TABLE IS NOT ENABLED FOR NOTIFICATIONS --
  1346.         if ObjectProperty(@objid, 'TableFulltextChangeTrackingOn') = 0
  1347.         begin
  1348.             -- SET STATE TO INACTIVE, SCHEMA-MODIFIED
  1349.             update sysobjects set status = ((status & ~72) | 128) where id = @objid
  1350.         end
  1351.         else
  1352.         begin
  1353.             -- SET STATE TO INACTIVE
  1354.             update sysobjects set status = (status & ~8) where id = @objid
  1355.         end
  1356.  
  1357.         -- DELETE SYSFULLTEXTNOTIFY ENTRIES
  1358.         delete sysfulltextnotify where tableid = @objid
  1359.  
  1360.         -- STOP EXISTING CRAWL (IMPLICIT STOP WITH WARNING)
  1361.         DBCC CALLFULLTEXT ( 12, @ftcatid, @objid, 2 )
  1362.         if @@error <> 0
  1363.             goto error_abort_exit
  1364.  
  1365.  
  1366.     end
  1367.  
  1368.     if @action = 'start_change_tracking'
  1369.     begin
  1370.         -- ERROR IF TABLE IS NOT ACTIVATED --
  1371.         if (ObjectProperty(@objid, 'TableHasActiveFulltextIndex') = 0)
  1372.         begin
  1373.             raiserror(15630,-1,-1, @tabname)
  1374.             goto error_abort_exit
  1375.         end
  1376.  
  1377.         -- ERROR IF TABLE IS ALREADY ENABLED FOR NOTIFICATIONS --
  1378.         if ObjectProperty(@objid, 'TableFulltextChangeTrackingOn') = 1
  1379.         begin
  1380.             raiserror(15631,-1,-1, @tabname)
  1381.             goto error_abort_exit
  1382.         end
  1383.  
  1384.         -- ERROR IF DATABASE IS IN SINGLE USER MODE --
  1385.         if DATABASEPROPERTY(db_name(), 'IsSingleUser') = 1
  1386.         begin
  1387.             raiserror(15637, -1, -1, @tabname)
  1388.             goto error_abort_exit
  1389.         end
  1390.  
  1391.         -- CHECK TO SEE IF THERE ARE ANY COLUMNS WHICH ARE NOT IN ROW BLOBS --
  1392.         if (select count(*) from syscolumns where
  1393.             (id = object_id(@tabname)) and ((xtype = 34) or (xtype = 35) or (xtype = 99)) and
  1394.             ((colstat & 16) != 0) and (length = 16)) > 0
  1395.         begin
  1396.             raiserror(15639, -1, -1, @tabname)
  1397.         end
  1398.  
  1399.         -- STOP EXISTING CRAWL
  1400.         DBCC CALLFULLTEXT ( 12, @ftcatid, @objid, 2 )
  1401.         if @@error <> 0
  1402.             goto error_abort_exit
  1403.  
  1404.         -- DELETE SYSFULLTEXTNOTIFY ENTRIES
  1405.         delete sysfulltextnotify where tableid = @objid
  1406.  
  1407.         select @schemamodified = ObjectProperty(@objid, 'TableIsFulltextSchemaModified')
  1408.  
  1409.         -- SET TABLE TO CT ON. SCHEMA MOD. OFF --
  1410.         update sysobjects set status = ((status & ~128) | 64) where id = @objid
  1411.  
  1412.         -- COMMIT TRAN -- NESCESSARY TO TURN ON CT BEFORE CRAWL IS KICKED OFF --
  1413.         commit tran
  1414.         if @@error <> 0
  1415.             goto error_abort_exit
  1416.  
  1417.         if (@schemamodified = 1)
  1418.         begin
  1419.             -- START A FULL POPULATION FOR THIS TABLE --
  1420.             DBCC CALLFULLTEXT ( 12, @ftcatid, @objid, 0 )
  1421.             if @@error <> 0
  1422.             begin
  1423.                 -- NEED TO RUN A FULL POPULATION
  1424.                 raiserror(15644, -1, -1,@tabname, 'start_full')
  1425.                 return 1
  1426.             end
  1427.         end
  1428.         else
  1429.         begin
  1430.             -- START AN INCREMENTAL POPULATION FOR THIS TABLE --
  1431.             DBCC CALLFULLTEXT ( 12, @ftcatid, @objid, 1 )
  1432.             if @@error <> 0
  1433.             begin
  1434.                 -- NEED TO RUN AN INCREMENTAL POPULATION
  1435.                 raiserror(15644, -1, -1, @tabname, 'start_incremental')
  1436.                 return 1
  1437.             end
  1438.         end
  1439.         return 0
  1440.  
  1441.     end
  1442.  
  1443.     if @action = 'stop_change_tracking'
  1444.     begin
  1445.         -- ERROR IF TABLE IS NOT ACTIVATED --
  1446.         if (ObjectProperty(@objid, 'TableHasActiveFulltextIndex') = 0)
  1447.         begin
  1448.             raiserror(15630,-1,-1, @tabname)
  1449.             goto error_abort_exit
  1450.         end
  1451.  
  1452.         if (ObjectProperty(@objid, 'TableFulltextChangeTrackingOn') = 0)
  1453.         begin
  1454.             rollback tran
  1455.                 return 0
  1456.         end
  1457.  
  1458.         if(ObjectProperty(@objid, 'TableFulltextPopulateStatus') != 0)
  1459.         begin
  1460.             raiserror(7640,-1,-1, @tabname)    
  1461.         end
  1462.  
  1463.         -- DISABLE FULLTEXT AUTO PROPAGATION (NO ERROR IF ALREADY DISABLED) --
  1464.         DBCC CALLFULLTEXT ( 9, @objid )    -- FTDisableNotify( db_id(), @objid )
  1465.         if @@error <> 0
  1466.             goto error_abort_exit
  1467.  
  1468.         -- TURN OFF ACTIVE BITS IN SYSOBJECTS --
  1469.         update sysobjects set status = status & ~192 where id = @objid
  1470.  
  1471.         if ((select count(*) from sysfulltextnotify where tableid = @objid) != 0)
  1472.         begin
  1473.             raiserror(7638,-1,-1, @tabname)
  1474.         end
  1475.  
  1476.         -- DELETE NOTIFICATIONS FROM SYSFULLTEXTNOTIFY --
  1477.         delete sysfulltextnotify where tableid = @objid
  1478.  
  1479.  
  1480.     end
  1481.  
  1482.     if @action = 'start_background_updateindex'
  1483.     begin
  1484.         -- ERROR IF TABLE IS NOT ACTIVATED --
  1485.         if ObjectProperty(@objid, 'TableHasActiveFulltextIndex') = 0
  1486.         begin
  1487.             raiserror(15630,-1,-1, @tabname)
  1488.             goto error_abort_exit
  1489.         end
  1490.  
  1491.  
  1492.         -- ERROR IF TABLE IS NOT ENABLED FOR NOTIFICATIONS --
  1493.         if ObjectProperty(@objid, 'TableFulltextChangeTrackingOn') = 0
  1494.         begin
  1495.             raiserror(15632,-1,-1, @tabname)
  1496.             goto error_abort_exit
  1497.         end
  1498.  
  1499.         -- ERROR IF FULLTEXT SCHEMA OF THE TABLE HAS BEEN MODIFIED (SHOULD NEVER HAPPEN)--
  1500.         if (ObjectProperty(@objid, 'TableIsFulltextSchemaModified') = 1)
  1501.         begin
  1502.             raiserror(15640,-1,-1, @tabname)
  1503.             goto error_abort_exit
  1504.         end
  1505.  
  1506.         -- ERROR IF TABLE IS ALREADY ENABLED FOR AUTO PROPAGATION --
  1507.         if ObjectProperty(@objid, 'TableFulltextBackgroundUpdateIndexOn') = 1
  1508.         begin
  1509.             raiserror(15633,-1,-1, @tabname)
  1510.             goto error_abort_exit
  1511.         end
  1512.  
  1513.         -- ENABLE TABLE FOR FULLTEXT AUTO PROPAGATION --
  1514.         DBCC CALLFULLTEXT ( 10, @ftcatid, @objid ) -- FTEnableAutoProp( @ftcatid, db_id(), @objid )
  1515.         if @@error <> 0
  1516.             goto error_abort_exit
  1517.  
  1518.         -- TURN ON FULLTEXT AUTOPROPAGATION BIT IN SYSOBJECTS --
  1519.         update sysobjects set status = status | 128 where id = @objid
  1520.     end
  1521.  
  1522.     if @action = 'stop_background_updateindex'
  1523.     begin
  1524.         -- ERROR IF TABLE IS NOT ACTIVATED --
  1525.         if (ObjectProperty(@objid, 'TableHasActiveFulltextIndex') = 0)
  1526.         begin
  1527.             raiserror(15630,-1,-1, @tabname)
  1528.             goto error_abort_exit
  1529.         end
  1530.  
  1531.         if (ObjectProperty(@objid, 'TableFullTextBackgroundUpdateIndexOn') = 0)
  1532.         begin
  1533.             rollback tran
  1534.             return 0
  1535.         end
  1536.  
  1537.         -- DISABLE FULLTEXT AUTO PROPAGATION (NO ERROR IF ALREADY DISABLED) --
  1538.         DBCC CALLFULLTEXT ( 9, @objid )    -- FTDisableNotify( db_id(), @objid )
  1539.         if @@error <> 0
  1540.             goto error_abort_exit
  1541.  
  1542.         -- TURN OFF ACTIVE BITS IN SYSOBJECTS --
  1543.         update sysobjects set status = status & ~128 where id = @objid
  1544.     end
  1545.  
  1546.     if @action = 'update_index'
  1547.     begin
  1548.  
  1549.         -- ERROR IF TABLE IS NOT ENABLED FOR NOTIFICATIONS --
  1550.         if ObjectProperty(@objid, 'TableFulltextChangeTrackingOn') = 0
  1551.         begin
  1552.             raiserror(15634,-1,-1, @tabname)
  1553.             goto error_abort_exit
  1554.         end
  1555.  
  1556.         -- ERROR IF TABLE IS NOT ACTIVE ANY MORE --
  1557.         if (ObjectProperty(@objid, 'TableHasActiveFulltextIndex') = 0)
  1558.         begin
  1559.             raiserror(15630,-1,-1, @tabname)
  1560.             goto error_abort_exit
  1561.         end
  1562.  
  1563.         -- ERROR IF FULLTEXT SCHEMA OF THE TABLE HAS BEEN MODIFIED -- THIS SHOULD NEVER HAPPEN
  1564.         if (ObjectProperty(@objid, 'TableIsFulltextSchemaModified') = 1)
  1565.         begin
  1566.             raiserror(15640,-1,-1, @tabname)
  1567.             goto error_abort_exit
  1568.         end
  1569.  
  1570.         -- ERROR IF DATABASE IS IN SIGNLE USER MODE --
  1571.         if DATABASEPROPERTY(db_name(), 'IsSingleUser') = 1
  1572.         begin
  1573.             raiserror(15637, -1, -1, @tabname)
  1574.             goto error_abort_exit
  1575.         end
  1576.  
  1577.         DBCC CALLFULLTEXT ( 11, @ftcatid, @objid )    -- FTStartPropagation( db_id(), @ftcatid, @objid )
  1578.         if @@error <> 0
  1579.             goto error_abort_exit
  1580.     end
  1581.  
  1582.     if @action = 'start_full'
  1583.     begin
  1584.         -- ERROR IF TABLE IS NOT ACTIVATED --
  1585.         if ObjectProperty(@objid, 'TableHasActiveFulltextIndex') = 0
  1586.         begin
  1587.             raiserror(15630,-1,-1, @tabname)
  1588.             goto error_abort_exit
  1589.         end
  1590.  
  1591.         -- ERROR IF DATABASE IS IN SINGLE USER MODE --
  1592.         if DATABASEPROPERTY(db_name(), 'IsSingleUser') = 1
  1593.         begin
  1594.             raiserror(15637, -1, -1, @tabname)
  1595.             goto error_abort_exit
  1596.         end
  1597.  
  1598.         -- RAISE WARNING IF POPULATE STATUS OF THE TABLE IS NOT IDLE
  1599.         if (ObjectProperty(@objid, 'TableFulltextPopulateStatus') != 0)
  1600.         begin
  1601.             raiserror(7636,-1,-1, @tabname)
  1602.             goto error_abort_exit
  1603.         end
  1604.  
  1605.         -- DELETE SYSFULLTEXTNOTIFY ENTRIES
  1606.         delete sysfulltextnotify where tableid = @objid
  1607.  
  1608.         -- START A FULL POPULATION FOR THIS TABLE --
  1609.         DBCC CALLFULLTEXT ( 12, @ftcatid, @objid, 0 )
  1610.         if @@error <> 0
  1611.             goto error_abort_exit
  1612.  
  1613.         if (ObjectProperty(@objid, 'TableIsFulltextSchemaModified') = 1)
  1614.         and (ObjectProperty(@objid, 'TableFulltextChangeTrackingOn') = 0)
  1615.             -- SET TABLE SCHEMA-UNMODIFIED
  1616.             update sysobjects set status = status & ~128 where id = @objid
  1617.  
  1618.     end
  1619.  
  1620.     if @action = 'start_incremental'
  1621.     begin
  1622.         -- ERROR IF TABLE IS NOT ACTIVATED --
  1623.         if ObjectProperty(@objid, 'TableHasActiveFulltextIndex') = 0
  1624.         begin
  1625.             raiserror(15630,-1,-1, @tabname)
  1626.             goto error_abort_exit
  1627.         end
  1628.  
  1629.         -- ERROR IF DATABASE IS IN SINGLE USER MODE --
  1630.         if DATABASEPROPERTY(db_name(), 'IsSingleUser') = 1
  1631.         begin
  1632.             raiserror(15637, -1, -1, @tabname)
  1633.             goto error_abort_exit
  1634.         end
  1635.  
  1636.         -- RAISE WARNING IF POPULATE STATUS OF THE TABLE IS NOT IDLE
  1637.         if (ObjectProperty(@objid, 'TableFulltextPopulateStatus') != 0)
  1638.         begin
  1639.             raiserror(7636,-1,-1, @tabname)
  1640.             goto error_abort_exit
  1641.         end
  1642.  
  1643.         -- DELETE SYSFULLTEXTNOTIFY ENTRIES
  1644.         delete sysfulltextnotify where tableid = @objid
  1645.  
  1646.         -- START AN INCREMENTAL POPULATION FOR THIS TABLE --
  1647.         if (ObjectProperty(@objid, 'TableIsFulltextSchemaModified') = 1)
  1648.             and (ObjectProperty(@objid, 'TableFulltextChangeTrackingOn') = 0)
  1649.             begin
  1650.             -- FULL CRAWL IF SCHEMA MODIFIED
  1651.             DBCC CALLFULLTEXT ( 12, @ftcatid, @objid, 0 )
  1652.             if @@error <> 0
  1653.                 goto error_abort_exit
  1654.  
  1655.             -- SET TABLE SCHEMA-UNMODIFIED
  1656.             update sysobjects set status = status & ~128 where id = @objid
  1657.         end
  1658.         else
  1659.         begin
  1660.             -- INCREMENTAL CRAWL
  1661.             DBCC CALLFULLTEXT ( 12, @ftcatid, @objid, 1 )
  1662.             if @@error <> 0
  1663.                 goto error_abort_exit
  1664.         end
  1665.     end
  1666.  
  1667.     if @action = 'stop'
  1668.     begin
  1669.         -- ERROR IF TABLE IS NOT ACTIVATED --
  1670.         if ObjectProperty(@objid, 'TableHasActiveFulltextIndex') = 0
  1671.         begin
  1672.             raiserror(15630,-1,-1, @tabname)
  1673.             goto error_abort_exit
  1674.         end
  1675.  
  1676.         -- ERROR IF POPULATE STATUS OF THE TABLE IS CRAWLING AND CT ON
  1677.         if (ObjectProperty(@objid, 'TableFulltextChangeTrackingOn') = 1)
  1678.         and ((ObjectProperty(@objid, 'TableFulltextPopulateStatus') = 1)
  1679.         or (ObjectProperty(@objid, 'TableFulltextPopulateStatus') = 2))
  1680.         begin
  1681.             raiserror(15642,-1,-1, @tabname)
  1682.             goto error_abort_exit
  1683.         end
  1684.  
  1685.         -- STOP A FULL/INCREMENTAL POPULATION FOR THIS TABLE --
  1686.         DBCC CALLFULLTEXT ( 12, @ftcatid, @objid, 2 )
  1687.         if @@error <> 0
  1688.             goto error_abort_exit
  1689.     end
  1690.  
  1691.     -- COMMIT TRAN --
  1692.     commit tran
  1693.     if @@error <> 0
  1694.         goto error_abort_exit
  1695.  
  1696.     -- SUCCESS --
  1697.     return 0
  1698.  
  1699. error_abort_exit:
  1700.     rollback tran
  1701.     return 1    -- sp_fulltext_table
  1702. go
  1703.  
  1704. create proc sp_fulltext_column
  1705.     @tabname        nvarchar(517),      -- table name
  1706.     @colname        sysname,            -- column name
  1707.     @action         varchar(20),        -- add | drop
  1708.     @language       int = null,         -- LCID of data in the column
  1709.     @type_colname   sysname = null      -- column name, valid if colname is img
  1710.  
  1711. as
  1712.     -- FULLTEXT MUST BE ACTIVE IN DATABASE --
  1713.     if DatabaseProperty(db_name(), 'IsFulltextEnabled') = 0
  1714.     begin
  1715.         raiserror(15601,-1,-1)
  1716.         return 1
  1717.     end
  1718.  
  1719.     -- VALIDATE PARAMS --
  1720.     if @action is null or @action not in ('add','drop')
  1721.     begin
  1722.         raiserror(15600,-1,-1,'sp_fulltext_column')
  1723.         return 1
  1724.     end
  1725.  
  1726.     -- DISALLOW USER TRANSACTION --
  1727.     set implicit_transactions off
  1728.     if @@trancount > 0
  1729.     begin
  1730.         raiserror(15002,-1,-1,'sp_fulltext_column')
  1731.         return 1
  1732.     end
  1733.  
  1734.     -- VALIDATE TABLE NAME --
  1735.     --    (1) Must exist in current database
  1736.     declare @objid int
  1737.     select @objid = object_id(@tabname, 'local')
  1738.     if @objid is null
  1739.     begin
  1740.         declare @curdbname sysname
  1741.         select @curdbname = db_name()
  1742.         raiserror(15009,-1,-1 ,@tabname, @curdbname)
  1743.         return 1
  1744.     end
  1745.     --    (2) Must be a user table
  1746.     if ObjectProperty(@objid, 'IsUserTable') = 0
  1747.     begin
  1748.         raiserror(15218,-1,-1 ,@tabname)
  1749.         return 1
  1750.     end
  1751.  
  1752.     -- CHECK PERMISSION ON TABLE --
  1753.     if (is_member('db_owner') = 0) AND (is_member('db_ddladmin') = 0)
  1754.         AND (is_member(user_name(ObjectProperty(@objid, 'ownerid'))) = 0)
  1755.     begin
  1756.         raiserror(15247,-1,-1)
  1757.         return 1
  1758.     end
  1759.  
  1760.     -- CHECK DATABASE MODE (must not be read-only) --
  1761.     if DATABASEPROPERTY(db_name(), 'IsReadOnly') = 1
  1762.     begin
  1763.         raiserror(15635, -1, -1, 'sp_fulltext_column')
  1764.         return 1
  1765.     end
  1766.  
  1767.     -- BEGIN TRAN AND LOCK TABLE --
  1768.     begin tran
  1769.     dbcc lockobjectschema(@tabname)
  1770.     if @@error <> 0
  1771.     begin
  1772.         goto error_abort_exit
  1773.     end
  1774.  
  1775.     -- CHECK FOR CATALOG IN SYSOBJECTS --
  1776.     declare @ftcatid smallint
  1777.     select @ftcatid = ObjectProperty(@objid, 'TableFulltextCatalogId')
  1778.  
  1779.     if @ftcatid = 0
  1780.     begin
  1781.         raiserror(15606,-1,-1,@tabname)
  1782.         goto error_abort_exit
  1783.     end
  1784.  
  1785.     -- VALIDATE COLUMN NAME (CANNOT BE COMPUTED) --
  1786.     declare @typename sysname
  1787.     select @typename = type_name(ColumnProperty(@objid, @colname, 'SystemType'))
  1788.     if @typename is null OR ColumnProperty(@objid, @colname, 'IsComputed') = 1
  1789.     begin
  1790.         raiserror(15104,-1,-1,@tabname,@colname)
  1791.         goto error_abort_exit
  1792.     end
  1793.  
  1794.     -- VALIDATE PARAMETERS
  1795.     if (@action <> 'add' or @typename <> N'image') and @type_colname is not null
  1796.     begin
  1797.         raiserror(15600, -1, -1, 'sp_fulltext_column')
  1798.         goto error_abort_exit
  1799.     end
  1800.  
  1801.     if @action = 'add'
  1802.     begin
  1803.         -- VALIDATE COLUMN TYPE --
  1804.         if @typename not in (N'nchar',N'nvarchar',N'ntext',N'char',N'varchar',N'text', N'image')
  1805.         begin
  1806.             raiserror(15611,-1,-1,@colname,@tabname)
  1807.             goto error_abort_exit
  1808.         end
  1809.  
  1810.         -- LANGUAGE
  1811.         if @language is null
  1812.             begin
  1813.                 -- USE THE SERVER DEFAULT WORD BREAKING LANGUAGE
  1814.                 select @language = value from master.dbo.syscurconfigs where config = 1126
  1815.             end
  1816.         else
  1817.             begin
  1818.                 -- VALIDATE @LANGUAGE ARGUMENT
  1819.                 if @language < 0
  1820.                 begin
  1821.                     raiserror(15600,-1,-1,'sp_fulltext_column')
  1822.                     goto error_abort_exit
  1823.                 end
  1824.             end
  1825.  
  1826.         update syscolumns set language = @language where id = @objid and name = @colname
  1827.  
  1828.         -- IF TABLE HAS ZERO INDEXED COLUMNS (THIS IS THE FIRST COLUMN TO BE ADDED), MARK IT ACTIVE
  1829.         if not exists (select * from syscolumns where id = @objid and (colstat & 16) = 16)
  1830.             and (ObjectProperty(@objid, 'TableFulltextChangeTrackingOn') = 0)
  1831.             and (ObjectProperty(@objid, 'TableIsFulltextSchemaModified') = 0)
  1832.         begin
  1833.             update sysobjects set status = (status  | 8) where id = @objid
  1834.         end
  1835.  
  1836.         -- SET THE BIT FOR THIS COLUMN --
  1837.         update syscolumns set colstat = colstat | 16 where id = @objid and name = @colname
  1838.  
  1839.         -- STOP A FULL/INCREMENTAL POPULATION FOR THIS TABLE --
  1840.         DBCC CALLFULLTEXT ( 12, @ftcatid, @objid, 2 )
  1841.         if @@error <> 0
  1842.             goto error_abort_exit
  1843.  
  1844.         if ObjectProperty(@objid, 'TableFulltextChangeTrackingOn') = 1
  1845.         begin
  1846.  
  1847.  
  1848.             if ObjectProperty(@objid, 'TableHasActiveFulltextIndex') = 1
  1849.             begin
  1850.  
  1851.                 -- DELETE SYSFULLTEXTNOTIFY ENTRIES
  1852.                 delete sysfulltextnotify where tableid = @objid
  1853.  
  1854.                 -- START A FULL CRAWL FOR THE TABLE
  1855.                 DBCC CALLFULLTEXT ( 12, @ftcatid, @objid, 0 )
  1856.                 if @@error <> 0
  1857.                     goto error_abort_exit
  1858.             end
  1859.  
  1860.         end
  1861.         else
  1862.         begin
  1863.  
  1864.             -- SET STATE TO SCHEMA_MODIFIED
  1865.             update sysobjects set status = ((status & ~64) | 128) where id = @objid
  1866.         end
  1867.  
  1868.         if @typename = N'image'
  1869.         begin
  1870.             -- VALIDATE THAT THE TYPE COLUMN IS GIVEN AND THAT IT IS VALID
  1871.             if @type_colname is null
  1872.             begin
  1873.                 raiserror(15600, -1, -1, 'sp_fulltext_column')
  1874.                 goto error_abort_exit
  1875.             end
  1876.  
  1877.             declare @typecolname sysname
  1878.             select @typecolname = type_name(ColumnProperty(@objid, @type_colname, 'SystemType'))
  1879.  
  1880.             -- TYPE COLUMN HAS TO BE A CHARACTER COLUMN
  1881.             if @typecolname not in (N'nchar',N'nvarchar',N'char',N'varchar')
  1882.             begin
  1883.                 raiserror(15600 , -1, -1, 'sp_fulltext_column')
  1884.                 goto error_abort_exit
  1885.             end
  1886.  
  1887.             -- ADD ENTRY OF COLID IN SYSDEPENDS
  1888.             declare @colid smallint
  1889.             declare @type_colid smallint
  1890.  
  1891.             select @colid = colid from syscolumns where [id] = @objid and name = @colname
  1892.             select @type_colid = colid from syscolumns where [id]  = @objid and name = @type_colname
  1893.  
  1894.             if not exists ( select [id] from sysdepends
  1895.                             where  [id] = @objid and
  1896.                                    depid = @objid and
  1897.                                    number = @colid )
  1898.             begin
  1899.                 insert into sysdepends ([id], depid, number, depnumber, status, deptype )
  1900.                         values( @objid, @objid, @colid, @type_colid, 0, 1)
  1901.             end
  1902.  
  1903.             -- SET BIT INDICATING TYPE COLUMN
  1904.             update syscolumns set colstat = colstat | 64 where id = @objid and name = @type_colname
  1905.         end
  1906.  
  1907.     end
  1908.     else
  1909.     begin
  1910.         -- CLEAR THE BIT & ZERO LCID FOR THIS COLUMN --
  1911.         update syscolumns set colstat = colstat & ~16, language = 0
  1912.             where id = @objid and name = @colname
  1913.  
  1914.         -- IF LAST COLUMN DROPPED
  1915.         if not exists (select * from syscolumns where id = @objid and (colstat & 16) = 16)
  1916.         begin
  1917.             -- STOP A FULL/INCREMENTAL POPULATION FOR THIS TABLE --
  1918.             DBCC CALLFULLTEXT ( 12, @ftcatid, @objid, 2 )
  1919.             if @@error <> 0
  1920.                 goto error_abort_exit
  1921.  
  1922.             -- IF TABLE HAS NOT BEEN DEACTIVATED
  1923.             if ((ObjectProperty(@objid, 'TableHasActiveFulltextIndex') = 1)
  1924.                 or (ObjectProperty(@objid, 'TableIsFulltextSchemaModified') = 0))
  1925.             begin
  1926.  
  1927.                 -- IF CHANGE-TRACKING IS OFF
  1928.                 if ObjectProperty(@objid, 'TableFulltextChangeTrackingOn') = 0
  1929.                 begin
  1930.                     -- SET TABLE TO SCHEMA UNMODIFIED, INACTIVE (TURN OFF ALL BITS)
  1931.                     update sysobjects set status = (status & ~200) where id = @objid
  1932.                 end
  1933.                 else
  1934.                 begin
  1935.                     -- SET TABLE TO INACTIVE
  1936.                     update sysobjects set status = (status & ~8) where id = @objid
  1937.                 end
  1938.             end
  1939.         end
  1940.         else
  1941.         if ObjectProperty(@objid, 'TableFulltextChangeTrackingOn') = 1
  1942.         begin
  1943.  
  1944.             -- STOP A FULL/INCREMENTAL POPULATION FOR THIS TABLE --
  1945.             DBCC CALLFULLTEXT ( 12, @ftcatid, @objid, 2 )
  1946.             if @@error <> 0
  1947.                 goto error_abort_exit
  1948.  
  1949.             if ObjectProperty(@objid, 'TableHasActiveFulltextIndex') = 1
  1950.             begin
  1951.                 -- DELETE SYSFULLTEXTNOTIFY ENTRIES
  1952.                 delete sysfulltextnotify where tableid = @objid
  1953.  
  1954.                 -- START A FULL CRAWL FOR THE TABLE
  1955.                 DBCC CALLFULLTEXT ( 12, @ftcatid, @objid, 0 )
  1956.                 if @@error <> 0
  1957.                     goto error_abort_exit
  1958.             end
  1959.  
  1960.         end
  1961.         else
  1962.         begin
  1963.  
  1964.             -- STOP A FULL/INCREMENTAL POPULATION FOR THIS TABLE --
  1965.             DBCC CALLFULLTEXT ( 12, @ftcatid, @objid, 2 )
  1966.             if @@error <> 0
  1967.                 goto error_abort_exit
  1968.  
  1969.             -- SET BITS IN SYSOBJECTS
  1970.             update sysobjects set status = ((status & ~64) | 128) where id = @objid
  1971.         end
  1972.  
  1973.         -- IF IMAGE COLUMN, UNBIND FROM THE TYPE COLUMN
  1974.         if @typename = N'image'
  1975.         begin
  1976.             declare @colid1 smallint
  1977.             declare @type_colid1 smallint
  1978.  
  1979.             select @colid1 = colid from syscolumns where [id] = @objid and name = @colname
  1980.             select @type_colid1 = depnumber from sysdepends
  1981.                     where [id] = @objid and
  1982.                          depid = @objid and
  1983.                          number = @colid1
  1984.  
  1985.             delete sysdepends where [id] = @objid and
  1986.                                     depid = @objid and
  1987.                                     number = @colid1 and
  1988.                                     depnumber = @type_colid1 and
  1989.                                     deptype = 1
  1990.  
  1991.             -- CLEAR BIT RELATING THE IMAGE COLUMN AND TYPE COLUMN
  1992.             if not exists ( select depnumber from sysdepends 
  1993.                             where    [id] = @objid and
  1994.                                     depnumber = @type_colid1 and
  1995.                                     deptype = 1 and
  1996.                                     number in (select colid from syscolumns 
  1997.                                              where    [id] = @objid and
  1998.                                                     type = 34 and
  1999.                                                     (colstat & 16) = 16) )
  2000.             begin
  2001.                 update syscolumns set colstat = colstat & ~64 where [id] = @objid and colid = @type_colid1
  2002.             end
  2003.         end
  2004.  
  2005.     end
  2006.  
  2007.     -- COMMIT TRAN --
  2008.     commit tran
  2009.     if @@error <> 0
  2010.         goto error_abort_exit
  2011.  
  2012.     -- SUCCESS --
  2013.     return 0
  2014.  
  2015. error_abort_exit:
  2016.     rollback tran
  2017.     return 1    -- sp_fulltext_column
  2018. go
  2019.  
  2020. create procedure sp_helptext
  2021. @objname nvarchar(776)
  2022. ,@columnname sysname = NULL
  2023. as
  2024.  
  2025. set nocount on
  2026.  
  2027. declare @dbname sysname
  2028. ,@BlankSpaceAdded   int
  2029. ,@BasePos       int
  2030. ,@CurrentPos    int
  2031. ,@TextLength    int
  2032. ,@LineId        int
  2033. ,@AddOnLen      int
  2034. ,@LFCR          int --lengths of line feed carriage return
  2035. ,@DefinedLength int
  2036.  
  2037. /* NOTE: Length of @SyscomText is 4000 to replace the length of
  2038. ** text column in syscomments.
  2039. ** lengths on @Line, #CommentText Text column and
  2040. ** value for @DefinedLength are all 255. These need to all have
  2041. ** the same values. 255 was selected in order for the max length
  2042. ** display using down level clients
  2043. */
  2044. ,@SyscomText    nvarchar(4000)
  2045. ,@Line          nvarchar(255)
  2046.  
  2047. Select @DefinedLength = 255
  2048. SELECT @BlankSpaceAdded = 0 /*Keeps track of blank spaces at end of lines. Note Len function ignores
  2049.                              trailing blank spaces*/
  2050. CREATE TABLE #CommentText
  2051. (LineId    int
  2052.  ,Text  nvarchar(255) collate database_default)
  2053.  
  2054. /*
  2055. **  Make sure the @objname is local to the current database.
  2056. */
  2057. select @dbname = parsename(@objname,3)
  2058.  
  2059. if @dbname is not null and @dbname <> db_name()
  2060.         begin
  2061.                 raiserror(15250,-1,-1)
  2062.                 return (1)
  2063.         end
  2064.  
  2065. /*
  2066. **  See if @objname exists.
  2067. */
  2068. if (object_id(@objname) is null)
  2069.         begin
  2070.         select @dbname = db_name()
  2071.         raiserror(15009,-1,-1,@objname,@dbname)
  2072.                 return (1)
  2073.         end
  2074.  
  2075. -- If second parameter was given.
  2076. if ( @columnname is not null)
  2077.     begin
  2078.         -- Check if it is a table
  2079.         if (select count(*) from sysobjects where id = object_id(@objname) and xtype in ('S ','U ','TF'))=0
  2080.             begin
  2081.                 raiserror(15218,-1,-1,@objname)
  2082.                 return(1)
  2083.             end
  2084.         -- check if it is a correct column name
  2085.         if ((select 'count'=count(*) from syscolumns where name = @columnname and id = object_id(@objname) and number = 0) =0)
  2086.             begin
  2087.                 raiserror(15645,-1,-1,@columnname)
  2088.                 return(1)
  2089.             end
  2090.     if ((select iscomputed from syscolumns where name = @columnname and id = object_id(@objname) and number = 0) = 0)
  2091.         begin
  2092.             raiserror(15646,-1,-1,@columnname)
  2093.             return(1)
  2094.         end
  2095.  
  2096.         DECLARE ms_crs_syscom  CURSOR LOCAL
  2097.         FOR SELECT text FROM syscomments WHERE id = object_id(@objname) and encrypted = 0 and number =
  2098.                         (select colid from syscolumns where name = @columnname and id = object_id(@objname) and number = 0)
  2099.                         order by number,colid
  2100.         FOR READ ONLY
  2101.  
  2102.     end
  2103. else
  2104.     begin
  2105.         /*
  2106.         **  Find out how many lines of text are coming back,
  2107.         **  and return if there are none.
  2108.         */
  2109.         if (select count(*) from syscomments c, sysobjects o where o.xtype not in ('S', 'U')
  2110.             and o.id = c.id and o.id = object_id(@objname)) = 0
  2111.                 begin
  2112.                         raiserror(15197,-1,-1,@objname)
  2113.                         return (1)
  2114.                 end
  2115.  
  2116.         if (select count(*) from syscomments where id = object_id(@objname)
  2117.             and encrypted = 0) = 0
  2118.                 begin
  2119.                         raiserror(15471,-1,-1)
  2120.                         return (0)
  2121.                 end
  2122.  
  2123.         DECLARE ms_crs_syscom  CURSOR LOCAL
  2124.         FOR SELECT text FROM syscomments WHERE id = OBJECT_ID(@objname) and encrypted = 0
  2125.                 ORDER BY number, colid
  2126.         FOR READ ONLY
  2127.     end
  2128.  
  2129. /*
  2130. **  Else get the text.
  2131. */
  2132. SELECT @LFCR = 2
  2133. SELECT @LineId = 1
  2134.  
  2135.  
  2136. OPEN ms_crs_syscom
  2137.  
  2138. FETCH NEXT FROM ms_crs_syscom into @SyscomText
  2139.  
  2140. WHILE @@fetch_status >= 0
  2141. BEGIN
  2142.  
  2143.     SELECT  @BasePos    = 1
  2144.     SELECT  @CurrentPos = 1
  2145.     SELECT  @TextLength = LEN(@SyscomText)
  2146.  
  2147.     WHILE @CurrentPos  != 0
  2148.     BEGIN
  2149.         --Looking for end of line followed by carriage return
  2150.         SELECT @CurrentPos =   CHARINDEX(char(13)+char(10), @SyscomText, @BasePos)
  2151.  
  2152.         --If carriage return found
  2153.         IF @CurrentPos != 0
  2154.         BEGIN
  2155.             /*If new value for @Lines length will be > then the
  2156.             **set length then insert current contents of @line
  2157.             **and proceed.
  2158.             */
  2159.             While (isnull(LEN(@Line),0) + @BlankSpaceAdded + @CurrentPos-@BasePos + @LFCR) > @DefinedLength
  2160.             BEGIN
  2161.                 SELECT @AddOnLen = @DefinedLength-(isnull(LEN(@Line),0) + @BlankSpaceAdded)
  2162.                 INSERT #CommentText VALUES
  2163.                 ( @LineId,
  2164.                   isnull(@Line, N'') + isnull(SUBSTRING(@SyscomText, @BasePos, @AddOnLen), N''))
  2165.                 SELECT @Line = NULL, @LineId = @LineId + 1,
  2166.                        @BasePos = @BasePos + @AddOnLen, @BlankSpaceAdded = 0
  2167.             END
  2168.             SELECT @Line    = isnull(@Line, N'') + isnull(SUBSTRING(@SyscomText, @BasePos, @CurrentPos-@BasePos + @LFCR), N'')
  2169.             SELECT @BasePos = @CurrentPos+2
  2170.             INSERT #CommentText VALUES( @LineId, @Line )
  2171.             SELECT @LineId = @LineId + 1
  2172.             SELECT @Line = NULL
  2173.         END
  2174.         ELSE
  2175.         --else carriage return not found
  2176.         BEGIN
  2177.             IF @BasePos <= @TextLength
  2178.             BEGIN
  2179.                 /*If new value for @Lines length will be > then the
  2180.                 **defined length
  2181.                 */
  2182.                 While (isnull(LEN(@Line),0) + @BlankSpaceAdded + @TextLength-@BasePos+1 ) > @DefinedLength
  2183.                 BEGIN
  2184.                     SELECT @AddOnLen = @DefinedLength - (isnull(LEN(@Line),0) + @BlankSpaceAdded)
  2185.                     INSERT #CommentText VALUES
  2186.                     ( @LineId,
  2187.                       isnull(@Line, N'') + isnull(SUBSTRING(@SyscomText, @BasePos, @AddOnLen), N''))
  2188.                     SELECT @Line = NULL, @LineId = @LineId + 1,
  2189.                         @BasePos = @BasePos + @AddOnLen, @BlankSpaceAdded = 0
  2190.                 END
  2191.                 SELECT @Line = isnull(@Line, N'') + isnull(SUBSTRING(@SyscomText, @BasePos, @TextLength-@BasePos+1 ), N'')
  2192.                 if LEN(@Line) < @DefinedLength and charindex(' ', @SyscomText, @TextLength+1 ) > 0
  2193.                 BEGIN
  2194.                     SELECT @Line = @Line + ' ', @BlankSpaceAdded = 1
  2195.                 END
  2196.             END
  2197.         END
  2198.     END
  2199.  
  2200.     FETCH NEXT FROM ms_crs_syscom into @SyscomText
  2201. END
  2202.  
  2203. IF @Line is NOT NULL
  2204.     INSERT #CommentText VALUES( @LineId, @Line )
  2205.  
  2206. select Text from #CommentText order by LineId
  2207.  
  2208. CLOSE  ms_crs_syscom
  2209. DEALLOCATE     ms_crs_syscom
  2210.  
  2211. DROP TABLE     #CommentText
  2212.  
  2213. return (0) -- sp_helptext
  2214. go
  2215.  
  2216. grant execute on sp_droplogin to public
  2217. grant execute on sp_addsrvrolemember to public
  2218. grant execute on sp_dropsrvrolemember to public
  2219. grant execute on sp_grantdbaccess to public
  2220. grant execute on sp_addalias to public
  2221. grant execute on sp_addrole to public
  2222. grant execute on sp_addapprole to public
  2223. grant execute on sp_change_users_login to public
  2224. grant execute on sp_fulltext_table to public
  2225. grant execute on sp_fulltext_column to public
  2226. grant execute on sp_helptext to public
  2227. go
  2228.  
  2229. --------------------------------------------------------------------------------
  2230. --    ODBC/OLEDB Catalog Procs (INSTCAT.SQL)
  2231. --------------------------------------------------------------------------------
  2232.  
  2233. if (exists (select * from sysobjects
  2234.         where name = 'sp_tableswc' and type = 'P '))
  2235.     drop proc sp_tableswc
  2236. go
  2237.  
  2238. print 'creating sp_tableswc'
  2239. go
  2240.  
  2241. create procedure sp_tableswc(
  2242.                @table_name        nvarchar(384)    = null,
  2243.                @table_owner     nvarchar(384)    = null,
  2244.                @table_qualifier sysname    = null,
  2245.                @table_type        varchar(100) = null)
  2246. as
  2247.     declare @databasename    sysname
  2248.     declare @qualprocname    nvarchar(141) /* 128 + '..sp_tables' */
  2249.  
  2250.     create table #sptables (
  2251.         TABLE_QUALIFIER sysname collate database_default null,
  2252.         TABLE_OWNER sysname collate database_default null,
  2253.         TABLE_NAME sysname collate database_default null,
  2254.         TABLE_TYPE    varchar(32) collate database_default null,
  2255.         REMARKS varchar(254) collate database_default null)
  2256.  
  2257.     declare databases CURSOR FOR
  2258.         select name from master..sysdatabases
  2259.         where name like @table_qualifier and name <> 'model' and has_dbaccess(name)=1
  2260.         for read only
  2261.  
  2262.     open databases
  2263.     fetch next from databases into @databasename
  2264.     while (@@FETCH_STATUS <> -1)
  2265.     begin
  2266.         if (charindex('%', @databasename) = 0)
  2267.         begin    /* skip dbnames w/wildcard characters to prevent loop */
  2268.             select @qualprocname = @databasename + '..sp_tables'
  2269.             insert into #sptables exec @qualprocname
  2270.                 @table_name, @table_owner, @databasename, @table_type
  2271.         end
  2272.         fetch next from databases into @databasename
  2273.     end
  2274.     deallocate databases
  2275.     select * from #sptables
  2276.         order by 4, 1, 2, 3
  2277. go
  2278.  
  2279. grant execute on sp_tableswc to public
  2280. go
  2281.  
  2282. -- Since we are updating the contents of instcat.sql and therefore the contents
  2283. -- of the ODBC/OLEDB catalog procs, we need to update the SPROC version
  2284.  
  2285. update spt_server_info 
  2286.     set attribute_value = '8.00.375'
  2287.     where attribute_id = 500
  2288. go
  2289.  
  2290. --------------------------------------------------------------------------------
  2291. --    End of SQLDMO System Procedures (SQLDMO.SQL)
  2292. --------------------------------------------------------------------------------
  2293.  
  2294.  
  2295. --------------------------------------------------------------------------------
  2296. -- END OF FILE: Turn off marking of system objects.
  2297. --    DO NOT ADD ANYTHING AFTER THIS POINT
  2298. --------------------------------------------------------------------------------
  2299. exec sp_MS_upd_sysobj_category 2
  2300. go
  2301.  
  2302. exec sp_configure 'allow updates',0
  2303. go
  2304.  
  2305. reconfigure with override
  2306. go
  2307.